package com.example.kakao01;

import java.util.ArrayList;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class MainActivity extends Activity {
	
	ListView listView;
	EditText addTitle;
	MyAdapter mAdapter;
	CheckBox check;

	MyData[] mData = { new MyData("",true) };

	ArrayList<MyData> mList = new ArrayList<MyData>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main2);

		listView = (ListView) findViewById(R.id.myListView);
		addTitle = (EditText) findViewById(R.id.addText);
		check = (CheckBox) findViewById(R.id.checkBox1);
		setData();

		mAdapter = new MyAdapter(this, mList);

		listView.setAdapter(mAdapter);

		Button btn = (Button) findViewById(R.id.add);
		btn.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {

				if (check.isChecked()) {
					String title = addTitle.getText().toString();
					MyData data = new MyData(title,true);
					mAdapter.add(data);
					addTitle.setText("");
				}
				else
				{
					String title = addTitle.getText().toString();
					MyData data = new MyData(title,false);
					mAdapter.add(data);
					addTitle.setText("");
				}
				
			}
		});
	}

	private void setData() {
		for (MyData str : mData) {
			mList.add(str);
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}
